<script type="text/javascript">

$(document).ready(function(){

$("#body-claim").on('change','#plan','select',function(){
	var index = $(this).attr('index');
	var value = $(this).val();
	if(value=='IP'){
	$("#tgl_claim2"+index).show();
	}else{
	$("#tgl_claim2"+index).hide();
	}
});
	
$("#btnTest").click(function()
{
	var nil = "";
   nil = $('input:radio[name=user]:checked').val()+" - "+$('input:radio[name=user]:checked').attr('nama_client');
   $("#policy_no").val(nil);
   $("#policy_no_hist_claim").val($('input:radio[name=user]:checked').val());
   $("#mst_client_id").val($('input:radio[name=user]:checked').attr('mst_client_id'));
   $("#reg_policy_id").val($('input:radio[name=user]:checked').attr('id_number'));
   $("#type_reg_policy").val($('input:radio[name=user]:checked').attr('typereg'));
}); 

$("#btn_tambah").click(function(){

var index = parseInt($("#index").val());

var indexi = index+1;

var html = '<tr>'+
			'<td>'+
				'<input type="text" maxlength="100" id="karyawan" name="karyawan[]" class="form-control input-width-medium">'+
				'<input class="form-control input-width-medium" type="hidden" maxlength="100" value="empty" name="id_anggota[]">'+
			'</td>'+

			'<td>'+
				'<input type="text" maxlength="100" id="peserta" name="peserta[]" class="form-control input-width-medium">'+
			'</td>'+
			
			'<td>'+
			'<select id="status" class="form-control input-width-small" name="status[]">'+
			'<option value="1">New Claim</option>'+
			'<option value="2">Ditunda</option>'+
			'<option value="3">Re-Claim</option>'+
			'<option value="4">Diterima</option>'+
			'<option value="5">Ditolak</option>'+
			'</select>'+
			'</td>'+
			
			'<td>'+
				'<input type="text" maxlength="20" id="no_reg" name="no_reg[]" class="form-control input-width-small">'+
			'</td>'+


			'<td>'+
				'<input type="text" id="tgl_claim" name="tgl_claim[]" data-mask="99-99-9999" class="form-control input-width-small">'+
				'<div id="tgl_claim2'+indexi+'" style="text-align:center;">sd'+
				'<input type="text" id="tgl_claim2" name="tgl_claim2[]" data-mask="99-99-9999" class="form-control input-width-small">'+
				'</div>'+
			'</td>'+

			'<td>'+
			'<select id="plan" class="form-control input-width-small" name="plan[]" index="'+indexi+'">'+
			'<option value="IP">IP</option>'+
			'<option value="OP">OP</option>'+
			'<option value="MA">MA</option>'+
			'<option value="VS">VS</option>'+
			'<option value="DE">DE</option>'+
			'<option value="KECELAKAAN">KECELAKAAN</option>'+
			'<option value="JIWA">JIWA</option>'+
			'<option value="MEDEVAC">MEDEVAC</option>'+
			'<option value="JENAZAH">JENAZAH</option>'+
			'</select>'+
			'</td>'+

			'<td>'+
				'<input type="text" id="nominal" name="nominal[]" class="form-control input-width-small">'+
			'</td>'+

			'<td>'+
				'<input type="text" id="jumlah_dibayar" name="jumlah_dibayar[]" class="form-control input-width-small">'+
			'</td>'+

			'<td>'+
				'<input type="text" id="tgl_pembayaran" name="tgl_pembayaran[]" data-mask="99-99-9999" class="form-control input-width-small">'+
			'</td>'+

			'<td>'+
				'<textarea id="remarks" name="remarks[]" class="form-control input-width-large"></textarea>'+
			'</td>'+
			
			'<td>'+
				'<textarea id="kelengkapan_dokumen" name="kelengkapan_dokumen[]" class="form-control input-width-large"></textarea>'+
			'</td>'+
			
		'</tr>';



$("#body-claim").prepend(html);

$("#index").val(indexi);

});

});

</script>

<div class="form">

    <?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm', array(
	'id'=>'trx-receipt-form',
	// Please note: When you enable ajax validation, make sure the corresponding
	// controller action is handling ajax validation correctly.
	// There is a call to performAjaxValidation() commented in generated controller code.
	// See class documentation of CActiveForm for details on this.
	'enableAjaxValidation'=>false,
)); ?>

    <!--<p class="help-block">Fields with <span class="required">*</span> are required.</p>-->

    <?php echo $form->errorSummary($model); ?>

            <div class="row">
	<div class="col-md-12">
				<div class="widget box">
				<div class="widget-header">

				<h4><i class="icon-reorder"></i>Data Polis</h4>
				<div class="controls">
				<div class="input-group">
					<input type="hidden" value="<?php echo $model->id; ?>" name="id_hist_claim" id="id_hist_claim" />
				 	<input id="policy_no" class="form-control input-width-large" type="hidden" name="policy_no" value="<?php echo $model->policy_no." - ".MstClient::model()->findByPk($model->mst_client_id)->name; ?>">
					<input type="hidden" name="HistClaim[policy_no]" id="policy_no_hist_claim" value="<?php echo $model->policy_no; ?>" />
					<input type="hidden" name="HistClaim[mst_client_id]" id="mst_client_id" value="<?php echo $model->mst_client_id; ?>" />
					<input type="hidden" name="HistClaim[reg_policy_id]" id="reg_policy_id" value="<?php echo $model->reg_policy_id; ?>" />
					<input type="hidden" name="HistClaim[type_reg_policy]" id="type_reg_policy" value="<?php echo $model->type_reg_policy; ?>" />
				</div>
				</div>

				<table>
				<tr>
				<td width="100"><strong>No Polis&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:<strong></td>
				<td><strong><?php echo $model->policy_no; ?></strong></td>
				</tr>
				<td width="100"><strong>Periode Polis&nbsp;:<strong></td>
				<td><strong><?php 
				if($model->type_reg_policy=='1'){
				echo date("d-m-Y",strtotime(RegHealthPolicy::model()->findByPk($model->reg_policy_id)->start_periode))." s/d ".date("d-m-Y",strtotime(RegHealthPolicy::model()->findByPk($model->reg_policy_id)->end_periode));
				}else{
				echo date("d-m-Y",strtotime(RegHealthPolicyNon::model()->findByPk($model->reg_policy_id)->start_periode))." s/d ".date("d-m-Y",strtotime(RegHealthPolicyNon::model()->findByPk($model->reg_policy_id)->end_periode));
				}
				?></strong></td>
				</tr>
				<tr>
				<td width="100"><strong>Klien&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:<strong></td>
				<td><strong><?php echo MstClient::model()->findByPk($model->mst_client_id)->name; ?></strong></td>
				</tr>
				</table>
				<br />

				<a href="#" id="btn_tambah" class="btn btn-sm btn-primary">Tambah Claim</a><br /><br />

				</div>
				

				<div class="widget-content no-padding">

				<table class="table table-hover table-striped table-bordered table-highlight-head">
	<thead>
		<tr>
			<!--<th>No</th>-->
			<th>Nama Karyawan</th>
			<th>Nama Peserta</th>
			<th>Status</th>
			<th>No Reg</th>
			<th>Tgl Pengobatan</th>
			<th>Manfaat</th>
			<th>Jumlah Claim</th>
			<th>Jumlah Dibayar</th>
			<th>Tgl Pembayaran</th>
			<th>Keterangan</th>
			<th>Kelengkapan Dokumen</th>
		</tr>
	</thead>
	<tbody id="body-claim">
		<input type="hidden" name="index" id="index" value="<?php echo count($data); ?>" />
		<?php 
		$i=1;
		foreach($data as $row){
			$status = HistClaimStatus::model()->find('id_hist_claim_anggota='.$row->id.' order by id desc')->status;
		?>
		<tr>
			<!--<td><span id="nomor"><?php //echo $i; ?></span></td>-->
			<td>
				<input class="form-control input-width-medium" type="hidden" maxlength="100" value="<?php echo $row->id ?>" name="id_anggota[]">
				<input class="form-control input-width-medium" type="hidden" maxlength="100" value="<?php echo HistClaimStatus::model()->find('id_hist_claim_anggota='.$row->id)->id; ?>" name="id_status[]">
				<?php echo $form->textField($modelAnggota,'karyawan', array('class'=>'form-control input-width-medium','name'=>'karyawan[]', 'value'=>$row->karyawan)); ?>
			</td>

			<td>
				<?php echo $form->textField($modelAnggota,'peserta', array('class'=>'form-control input-width-medium','name'=>'peserta[]', 'value'=>$row->peserta)); ?>
			</td>

			<td>
				<?php echo $form->dropDownList($modelStatus, 'status', array(
			'1' => "New Claim",	
			'2' => "Ditunda",
			'3' => "Re-Claim",
			'4' => "Diterima",
			'5' => "Ditolak",
			),array('class'=>'form-control input-width-small','name'=>'status[]', 'options' => array($status=>array('selected'=>true)))); ?>
			</td>

			<td>
				<?php echo $form->textField($modelAnggota,'no_reg', array('class'=>'form-control input-width-small','name'=>'no_reg[]', 'value'=>$row->no_reg)); ?>
			</td>


			<td>
				<?php echo $form->textField($modelAnggota,'tgl_claim', array('class'=>'form-control input-width-small','data-mask'=>"99-99-9999", 'name'=>'tgl_claim[]', 'value'=>$row->tgl_claim=='1970-01-01 00:00:00' ? '' : date('d-m-Y',strtotime($row->tgl_claim)))); ?>
				<div id="tgl_claim2<?php echo $i; ?>" style="text-align:center;">
				s/d
				<?php echo $form->textField($modelAnggota,'tgl_claim2', array('class'=>'form-control input-width-small','data-mask'=>"99-99-9999", 'name'=>'tgl_claim2[]', 'value'=>$row->tgl_claim2=='1970-01-01 00:00:00' ? '' : date('d-m-Y',strtotime($row->tgl_claim2)))); ?>
				</div>
			</td>

			<td>
			<?php echo $form->dropDownList($modelAnggota, 'plan', array('IP' => "IP",
			'IP' => "IP",
			'OP' => "OP",
			'MA' => "MA",
			'VS' => "VS",
			'DE' => "DE",
			'KECELAKAAN' => "KECELAKAAN",
			'JIWA' => "JIWA",
			'MEDEVAC' => "MEDEVAC",
			'JENAZAH' => "JENAZAH"
			),array('class'=>'form-control input-width-small','name'=>'plan[]', 'options' => array($row->plan=>array('selected'=>true)))); ?>
			</td>

			<td>
				<?php echo $form->textField($modelAnggota,'nominal', array('class'=>'form-control input-width-small','name'=>'nominal[]', 'value'=>$row->nominal)); ?>
			</td>

			<td>
				<?php echo $form->textField($modelAnggota,'jumlah_dibayar', array('class'=>'form-control input-width-small','name'=>'jumlah_dibayar[]', 'value'=>$row->jumlah_dibayar)); ?>
			</td>

			<td>
				<?php echo $form->textField($modelAnggota,'tgl_pembayaran', array('class'=>'form-control input-width-small','data-mask'=>"99-99-9999", 'name'=>'tgl_pembayaran[]', 'value'=>$row->tgl_pembayaran=='1970-01-01 00:00:00' ? '' : date('d-m-Y',strtotime($row->tgl_pembayaran)))); ?>
			</td>

			<td>
				<?php echo $form->textArea($modelStatus,'remarks', array('class'=>'form-control input-width-large','name'=>'remarks[]', 'value'=>HistClaimStatus::model()->find('id_hist_claim_anggota='.$row->id.' order by id desc')->remarks)); ?>
			</td>
			
			<td>
				<?php echo $form->textArea($modelStatus,'kelengkapan_dokumen', array('class'=>'form-control input-width-large','name'=>'kelengkapan_dokumen[]', 'value'=>HistClaimStatus::model()->find('id_hist_claim_anggota='.$row->id.' order by id desc')->kelengkapan_dokumen)); ?>
			</td>
			
		</tr>



		<?php 
		$i++;
		}
		?>


		
	</tbody>
</table>	



							</div>
						</div>
					</div>
	</div>

        <div class="form-actions">
        <?php echo TbHtml::submitButton($model->isNewRecord ? 'Create' : 'Save',array(
		    'color'=>TbHtml::BUTTON_COLOR_PRIMARY,
		    'size'=>TbHtml::BUTTON_SIZE_LARGE,
		)); ?>
    </div>

    <?php $this->endWidget(); ?>

</div><!-- form -->


	<div id="myModal" class="modal fade in" style="display: none;" aria-hidden="false">
												<div class="modal-dialog" style="width:800px;">
													<div class="modal-content">
														<div class="modal-header">
															<button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
															<h4 class="modal-title">Pilih Client</h4>
														</div>
														<div class="modal-body">
															
															<?php echo $this->renderPartial('_viewClient', array('model'=>$modelClient, 'modelClientNonHealth'=>$modelClientNonHealth));  // I need $productId to by dynamic related to link 
                ?> 
														</div>
														<div class="modal-footer">
															<button data-dismiss="modal" class="btn btn-default" type="button">Close</button>
															<button id="btnTest" data-dismiss="modal" class="btn btn-primary" type="button">Pilih</button>
														</div>
													</div><!-- /.modal-content -->
												</div><!-- /.modal-dialog -->
	</div>




